package com.econvent.common.conn;

import lombok.extern.slf4j.Slf4j;

/**
 * 动态的添加数据源
 *
 * @author xiekun
 * @since 1.0
 */

@Slf4j
public class DynamicDataSourceContextHolder {
    /**
     * init the dataBase of ecology
     * */
    private static final ThreadLocal<String> contextHolder  = new ThreadLocal<String>() {
        @Override
        protected String initialValue() {
            return "ecology";
        }
    };

    /**
     * To switch DataSource
     *
     * @param key the key
     */
    public static void setDataSourceKey(String key) {
        contextHolder.set(key);
    }

    /**
     * Get current DataSource
     *
     * @return data source key
     */
    public static String getDataSourceKey() {
        return contextHolder.get();
    }

    /**
     * To set DataSource as default
     */
    public static void clearDataSourceKey() {
        contextHolder.remove();
    }
}
